package com.xsir.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xsir.common.Result;
import com.xsir.entity.Category;
import com.xsir.service.ICategoryService;
import com.xsir.util.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xsir
 * @since 2020-11-03
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private ICategoryService categoryService;
    
    @GetMapping("/author")
    public Result author(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        Integer uid = (Integer) JwtUtil.decode(token).get("uid");
        List<Category> categories = categoryService.list(new QueryWrapper<Category>().eq("user_id", uid));
        return Result.ok(categories);
    }
}
